<?php
namespace backend\controllers;

use Yii;
use backend\models\system\ShareFrom;
use backend\controllers\BaseController;
use backend\models\system\IndexForm;
use backend\models\system\TopnavForm;
use backend\models\system\SysConfig;
use backend\models\system\FriendLink;
use backend\models\system\SettingserviceFrom;
use backend\models\system\UserregForm;
use backend\models\system\UserLoginForm;
use backend\models\system\ValidationcodeForm;
use backend\models\system\CourseForm;
use backend\models\system\DirectSeeding;
use backend\models\system\DefaultForm;
use backend\models\system\ConsultForm;
use backend\models\system\CoinForm;
use backend\models\system\ChangecoinForm;
use backend\models\system\IpblackForm;
use backend\models\system\EmailForm;
use backend\models\site\AdminLog;
use backend\models\site\AdminLogForm;
use backend\models\user\Admin;
use yii\widgets\LinkPager;
use yii\web\UploadedFile;
use yii\data\Pagination;
use yii\bootstrap\Alert;
use yii\helpers\ArrayHelper;
use common\components\FileToken;



/**
 * 系统功能模块
 * @author 王明东
 */
class SystemController extends BaseController
{
	public $model;
	public $pagination;
    /**
     *  站点设置--基础信息设置
     *  1代表站点设置 | 基础信息
     */
    public function actionIndex()
    {
        $model = new IndexForm();
        
        //验证数据
        if ( $model->load(Yii::$app->request->post()) && $model->validate() ) 
        {
            //获取上传实例
            $model->logo = UploadedFile::getInstance($model, 'logo');
            $model->icon = UploadedFile::getInstance($model, 'icon');
            $data = Yii::$app->request->post('IndexForm');
            unset($data['logo']);
            unset($data['icon']);
            
            //上传
            if (($model->logo || $model->icon) && $path_info = $model->upload()) {
               $data = ArrayHelper::merge($data, $path_info);
            }
            //保存数据
            SysConfig::saveValue($data);

            $this->success('配置成功！');
        } 
        else 
        {
            //查询站点配置项
            $model->config_type = 1;
            $data = $model->getValueByType();

            //加载属性值
            $data = ArrayHelper::mapNormal($data, 'config_key', 'config_value');
            $model->attributes = $data;
            return $this->render('index', ['model' => $model]);
        }
        
    }

    /**
     * 站点设置--主题设置
     
    public function actionTheme()
    {
        return $this->render('theme');
    }
    */
    /**
     * 站点设置--邮件服务器设置
     */
    public function actionEmail()
    {
	    $model = new EmailForm();
	    $model ->config_type = 3;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('email',['model'=>$model]);
    }

	/**
	 * 站点设置--邮件服务器设置修改
	 */
	public function actionEmailsave()
	{
		$model = new EmailForm();
		if ($model->load(Yii::$app->request->post()) && $model->validate())
		{
			$data = Yii::$app->request->post("EmailForm");
			SysConfig::saveValue($data,3);
			$this->success('修改成功！', ['system/email']);
		}
		else
		{
			$this->error('修改失败！', ['system/email']);
		}
	}

    /**
     *  站点设置--顶部导航设置
     *  config_type    4  代表站点设置 | 顶部导航设置
     *  config_value   1  为开启状态    2  为关闭状态
     */
    public function actionTopnav()
    {
        $model = new TopnavForm();
        
        $model ->config_type = 4;
        $data = $model->getValueByType();
        foreach($data as $k=>$v)
        {
            $data[$k]['config_value'] = unserialize($v['config_value']);
        }
        return $this->render('topnav', [
            'model' => $model,
            'data' => $data
        ]);
    }

    /**
     * @inheritdoc  站点设置--顶部导航修改页面 ajax
     *       config_type    4  代表站点设置 | 顶部导航设置
     *      config_value   1  为开启状态    2  为关闭状态
     */
    public function actionTopnavupdate()
    {
        $model = new TopnavForm();
        $config_id = Yii::$app->request->post("config_id");
        $model->config_id = $config_id;
        $db = $model->getValueById();
        $db['config_value'] = unserialize($db['config_value']);
        $model->config_key = $db['config_key'];
        $model->config_type = $db['config_type'];
        $model->nav_name = $db['config_value']['nav_name'];
        $model->nav_url = $db['config_value']['nav_url'];
        $model->nav_status = $db['config_value']['nav_status'];
        return $this->renderPartial("topnavupdate",['model'=>$model]);
    }

    /**
     * @inheritdoc  站点设置--顶部导航修改
     *       config_type    4  代表站点设置 | 顶部导航设置
     *      config_value   1  为开启状态    2  为关闭状态
     */
    public function actionTopnavupd()
    {

        $model = new TopnavForm();
        if ($model->load(Yii::$app->request->post()) && $model->validate())
        {
            SysConfig::saveValueid();
            $this->success('修改成功！', ['system/topnav']);
        }
        else
        {
            $this->error('修改失败！', ['system/topnav']);
        }
    }

    /**
     * @inheritdoc  站点设置--顶部导航添加
     *       config_type    4  代表站点设置 | 顶部导航设置
     *      config_value   1  为开启状态    2  为关闭状态
     */
    public function actionTopnavadd()
    {
        $model = new TopnavForm();
        if ($model->load(Yii::$app->request->post()) && $model->validate())
        {
            $data = Yii::$app->request->post('TopnavForm');
            $config_key = $data['config_key'];
            $config_type = $data['config_type'];
            unset($data['config_key']);
            unset($data['config_type']);
            $config_value = serialize($data);

            $model->config_key = $config_key;
            $model->config_type = 4;
            $model->config_value = $config_value;
            $model->save();
            $this->success('添加成功！', ['system/topnav']);
        }
        else
        {
            $this->error('验证失败！', ['system/topnav']);
        }
    }

    /**
     * @inheritdoc  站点设置--顶部导航删除
     */
    public function actionTopnavdel()
    {
        if(Yii::$app->request->isPost)
        {
            $config_id = Yii::$app->request->post("config_id");
            $model = new TopnavForm();
            $customer = $model->findOne($config_id);
            $re = $customer->delete();
            if($re)
            {
                echo 1;die;//删除成功
            }else{
                echo 0;die;//删除失败
            }
        }else{
            echo 2;die;//没有参数
        }
    }

    /**
     * @inheritdoc  站点设置--底部导航设置
     *
     */
    public function actionBottomnav()
    {
        $model = new FriendLink();
        $friendlink = $model->friendlinksel();
        return $this->render('bottomnav',[
            'model'=>$model,
            'friendlink'=>$friendlink,
        ]);
    }

    /**
     * @inheritdoc  站点设置--底部导航添加
     */
    public function actionFriendlinkadd()
    {
        //print_r(Yii::$app->request->post('FriendLink'));die;
        $model = new FriendLink();
        if (Yii::$app->request->isPost) {
            $img = UploadedFile::getInstance($model, 'link_logo');
            if ($img) {
                $filename = time() . rand(1000, 9999) .".".$img->extension;
                $img->saveAs('uploads/friendlink/' .$filename);
                $model->attributes = Yii::$app->request->Post('FriendLink');
                $model->link_logo = "uploads/friendlink/".$filename;
                if ($model->save()) {
                    $this->success('保存成功！', ['system/bottomnav']);
                } else {
                    $this->error('保持失败！');
                }
            }
        }
    }

	/**
	 * @inheritdoc  站点设置--底部导航删除
	 */
	public function actionFriendlinkdel()
	{
		if(Yii::$app->request->isPost)
		{
			$config_id = Yii::$app->request->post("config_id");
			$model = new FriendLink();
			$customer = $model->findOne($config_id);
			$re = $customer->delete();
			if($re)
			{
				echo 1;die;//删除成功
			}else{
				echo 0;die;//删除失败
			}
		}else{
			echo 2;die;//没有参数
		}
	}

	/**
	 * @inheritdoc  站点设置--底部导航修改页面
	 */
	public function actionFriendlinkupdate()
	{
		$model = new FriendLink();
		if(Yii::$app->request->isPost){
			$link_id = Yii::$app->request->post("link_id");
			$model->link_id = $link_id;
			$db = $model->friendlinkByid();
			$model->link_id = $db['link_id'];
			$model->link_name = $db['link_name'];
			$model->link_url = $db['link_url'];
			$model->link_logo = $db['link_logo'];
			$model->link_order = $db['link_order'];
			return $this->renderPartial("friendlinkupdate",['model'=>$model]);
		}else{
			$this->redirect(['system/bottomnav']);
		}
	}

	/**
	 * @inheritdoc  站点设置--底部导航修改
	 */
	public function actionFriendlinkupd()
	{
		$data = Yii::$app->request->post('FriendLink');
		$link_id = $data['link_id'];
		$model = new FriendLink();
		$model = $model->findOne($link_id);
		if (Yii::$app->request->isPost) {
			$model->attributes = Yii::$app->request->Post('FriendLink');
			$img = UploadedFile::getInstance($model, 'link_logo');
			if ($img) {
				$filename = time() . rand(1000, 9999) . "." . $img->extension;
				$img->saveAs('uploads/friendlink/' . $filename);
				$model->link_logo = "uploads/friendlink/" . $filename;
			}else{
				$model->link_logo = $model->oldAttributes['link_logo'];
			}
            if ($model->save())
            {
                $this->success('修改成功！', ['system/bottomnav']);
            }
            else
            {
                $this->error('修改失败！', ['system/bottomnav']);
            }
		}
	}

    /**
     * @inheritdoc  站点设置--客服设置
     */
    public function actionConsult()
    {
	    $model = new SettingserviceFrom();
	    $service = $model->servicesel();
	    foreach($service as $k=>$v)
	    {
		    //QQ配置信息
		    if($v['config_key'] == 'qq_message')
		    {
			    $qq_message = explode("|",$v['config_value']);
			    foreach ($qq_message as $key => $val)
			    {
				    $qq_message[$key] = explode(",",$val);
		        }
		    }

		    //QQ群配置信息
		    if($v['config_key'] == 'qq_group')
		    {
			    $qq_group = explode("|",$v['config_value']);
			    foreach ($qq_group as $key => $val)
			    {
				    $qq_group[$key] = explode(",",$val);
			    }
		    }

		    //联系电话配置信息
		    if($v['config_key'] == 'phone_message')
		    {
			    $phone_message = explode("|",$v['config_value']);
			    foreach ($phone_message as $key => $val)
			    {
				    $phone_message[$key] = explode(",",$val);
			    }
		    }

		    $model->$v['config_key'] = $v['config_value'];
		    $model->config_id = $v['config_id'];
		    $model->config_type = $v['config_type'];
	    }
        return $this->render('consult',['model'=>$model,'qq_message'=>$qq_message,'qq_group'=>$qq_group,'phone_message'=>$phone_message]);
    }

	/**
	 * @inheritdoc  站点设置--客服修改
	 */
	public function actionSettingservicesave()
	{
		$model = new SettingserviceFrom();
		$data = Yii::$app->request->post();
		$SettingserviceFrom = $data['SettingserviceFrom'];
		$qq = $data['qq'];
		foreach($qq as $k=>$v)
		{
			$SettingserviceFrom['qq_message'].=$v['name'].",".$v['number']."|";
		}

		$SettingserviceFrom['qq_message'] = substr($SettingserviceFrom['qq_message'],0,-1);

		$qqgroup = $data['qqgroup'];
		foreach($qqgroup as $k=>$v)
		{
			$SettingserviceFrom['qq_group'].=$v['name'].",".$v['number']."|";
		}
		$SettingserviceFrom['qq_group'] = substr($SettingserviceFrom['qq_group'],0,-1);

		$phone = $data['phone'];
		foreach($phone as $k=>$v)
		{
			$SettingserviceFrom['phone_message'].=$v['name'].",".$v['number']."|";
		}
		$SettingserviceFrom['phone_message'] = substr($SettingserviceFrom['phone_message'],0,-1);

		foreach ( $SettingserviceFrom as $key=>$value ) {
			if($key == "wechat_code")
			{
				$model = SysConfig::find()->where(['config_key'=>$key])->one();
				//print_r($model);die;
				if(!empty($SettingserviceFrom['wechat_code']))
				{
					$model->config_value = $value;
				}
				else
				{
					$model->config_value = $model->oldAttributes['config_value'];
				}
			}
			else
			{
				$model = SysConfig::find()->where(['config_key'=>$key])->one();
				$model->config_value = $value;
			}

			$model->save();
		}
		$this->redirect(['system/consult']);
	}

    /**
     * @inheritdoc  站点设置--侧边栏
     */
    public function actionSidebar()
    {
        return $this->render('sidebar');
    }

    /**
     * @inheritdoc  站点设置--分享
     */
    public function actionShare()
    {
	    $model = new ShareFrom();
	    $model->config_type = 8;
	    $data = $model->getValue();
	    foreach($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('share',['model'=>$model]);
    }

	/**
	 * @inheritdoc  站点设置--分享修改
	 */
	public function actionSharesave()
	{
		$model = new ShareFrom();
		if($data = Yii::$app->request->post('ShareFrom'))
		{
			foreach ( $data as $key=>$value )
			{
				$model = SysConfig::find()->where(['config_key'=>$key])->one();
				$model->config_value = $value;
				$model->save();
			}
		}
		$this->redirect(['system/share']);
	}



    /**
     * @inheritdoc  用户设置--用户信息
     
    public function actionUser()
    {
        return $this->render('user');
    }
    */
    /**
     * @inheritdoc  用户设置--登陆
     */
    public function actionUserlogin()
    {
	    $model = new UserLoginForm();
	    $model->config_type = 11;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
		    if($v['config_key'] == "protect_one")
		    {
			    $protect_one = unserialize($v['config_value']);
			    $model ->protect_one_num = $protect_one['num'];
		    }
		    else if($v['config_key'] == "protect_two")
		    {
			    $protect_two = unserialize($v['config_value']);
			    $model->protect_two_num  =  $protect_two['num'];
			    $model->protect_two_time = $protect_two['time'];
		    }
		    else
		    {
			    $model ->$v['config_key'] = $v['config_value'];
		    }
	    }
        return $this->render('userlogin',['model'=>$model]);
    }

	/**
	 * @inheritdoc  用户设置--登陆设置修改
	 */
	public function actionUserloginsave()
	{
		$model = new UserLoginForm();
		if($model->load(Yii::$app->request->post()) && $model->validate())
		{
			$data = Yii::$app->request->post("UserLoginForm");
			$data['protect_one'] = serialize(['num'=>$data['protect_one_num'],'time'=>"10"]);
			$data['protect_two'] = serialize(['num'=>$data['protect_two_num'],'time'=>$data['protect_two_time']]);
			unset($data['protect_one_num']);
			unset($data['protect_two_num']);
			unset($data['protect_two_time']);
			SysConfig::saveValue($data, 11);
            $this->success('修改成功', ['system/userlogin']);
		}else{
            $this->error('修改失败', ['system/userlogin']);
		}
	}

    /**
     * @inheritdoc  用户设置--注册
     */
    public function actionUserreg()
    {
	    $model = new UserregForm();
	    $model->config_type=10;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
			$model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('userreg',['model'=>$model]);
    }

	/**
	 * @inheritdoc  用户设置--注册修改
	 */
	public function actionUserregsave()
	{
		$model = new UserregForm();
		if ($model->load(Yii::$app->request->post()) && $model->validate()){
			$data = Yii::$app->request->post('UserregForm');
			SysConfig::saveValue($data,$type=10);
            $this->success('修改成功！', ['system/userreg']);
		}else{
            $this->error('修改失败！', ['system/userreg']);
		}
	}
    /**
     * @inheritdoc  用户设置--默认头像
     */
    public function actionUseravatar()
    {
	    $model = new ValidationcodeForm();
	    $model->config_type = 12;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('useravatar',['model'=>$model]);
    }

	/**
	 * @inheritdoc  用户设置--默认头像修改
	 */
	public function actionUseravatarsave()
	{
		$model = new ValidationcodeForm();
		$data = Yii::$app->request->post("ValidationcodeForm");
		$model = SysConfig::find()->where(['config_key'=>'default_photo'])->one();
		if(!empty($data['default_photo']))
		{
			$model->config_value = $data['default_photo'];
		}
		else
		{
			$model->config_value = $model->oldAttributes['config_value'];
		}

		$re = $model->save();
		if($re)
		{
            $this->success('修改成功！', ['system/useravatar']);
		}
		else
		{
            $this->error('修改失败！', ['system/useravatar']);
		}
	}

    /**
     * @inheritdoc  课程设置--课程
     */
    public function actionCourse()
    {
	    $model = new CourseForm();
	    $model->config_type = 13;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('course',['model'=>$model]);
    }

	/**
	 * @inheritdoc  课程设置--课程修改
	 */
	public function actionCoursesave()
	{
		$model = new CourseForm();
		if($model->load(Yii::$app->request->post()) && $model->validate())
		{
			$data = Yii::$app->request->post("CourseForm");
			SysConfig::saveValue($data,$type=13);
            $this->success('修改成功！', ['system/course']);
		}
		else
		{
            $this->error('修改失败！', ['system/course']);
		}
	}

    /**
     * @inheritdoc  课程设置--直播
     */
    public function actionLive()
    {
	    $model = new DirectSeeding();
	    $model->config_type = 14;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('live',['model'=>$model]);
    }

	/**
	 * @inheritdoc  课程设置--直播修改
	 */
	public function actionLivesave()
	{
		$model = new DirectSeeding();
		if($model->load(Yii::$app->request->post()) && $model->validate())
		{
			$data = Yii::$app->request->post("DirectSeeding");
			SysConfig::saveValue($data,$type=14);
            $this->success('修改成功！', ['system/live']);
		}
		else
		{
            $this->error('修改失败！', ['system/live']);
		}
	}

    /**
     * @inheritdoc  课程设置--默认图片
     */
    public function actionDefault()
    {
	    $model = new DefaultForm();
	    $model->config_type = 15;
	    $data = $model->getValueByType();
	    foreach ($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
	    return $this->render('default',['model'=>$model]);
    }

	/**
	 * @inheritdoc  课程设置--默认图片修改
	 */
	public function actionDefaultsave()
	{
		$model = new DefaultForm();
		$data = Yii::$app->request->post("DefaultForm");
		$model = SysConfig::find()->where(['config_key'=>'course_photo'])->one();
		//$model->config_value = $data['course_photo'];
		if(!empty($data['course_photo']))
		{
			$model->config_value = $data['course_photo'];
		}
		else
		{
			$model->config_value = $model->oldAttributes['config_value'];
		}
		$re = $model->save();
		if($re)
		{
            $this->success('修改成功！', ['system/default']);
		}
		else
		{
            $this->error('修改失败！', ['system/default']);
		}
	}

    /**
     * @inheritdoc  运营设置
     */
    public function actionOperate()
    {
	    $model = new ConsultForm();
	    $model -> config_type = 16;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('operate',['model'=>$model]);
    }

	/**
	 * @inheritdoc  运营设置修改
	 */
	public function actionOperatesave()
	{
		$model = new ConsultForm();
		if($model->load(Yii::$app->request->post()) && $model->validate())
		{
			$data = Yii::$app->request->post('ConsultForm');
			SysConfig::saveValue($data,$type=16);
            $this->success('修改成功！', ['system/operate']);
		}
		else
		{
            $this->error('修改失败！', ['system/operate']);
		}
	}

    /**
     * @inheritdoc  财务设置--支付
     */
    public function actionCoin()
    {
	    $model = new CoinForm();
	    $model->config_type = 17;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('coin',['model'=>$model]);
    }

	/**
	 * @inheritdoc  财务设置--支付修改
	 */
	public function actionCoinsave()
	{
		$model = new CoinForm();
		if($model->load(Yii::$app->request->post()) && $model->validate())
		{
			$data = Yii::$app->request->post("CoinForm");
			SysConfig::saveValue($data,$type = 17);
            $this->success('修改成功！', ['system/coin']);
		}
		else
		{
            $this->error('修改失败！', ['system/coin']);
		}
	}

    /**
     * @inheritdoc  财务设置--充值
     */
    public function actionChangecoin()
    {
		$model = new ChangecoinForm();
	    $model ->config_type = 18;
	    $data = $model->getValueByType();
	    foreach($data as $k=>$v)
	    {
		    $model->$v['config_key'] = $v['config_value'];
	    }
        return $this->render('changecoin',['model'=>$model]);
    }

	/**
	 * @inheritdoc  财务设置--充值修改
	 */
	public function actionChangecoinsave()
	{
		$model = new ChangecoinForm();
		if($model->load(Yii::$app->request->post()) && $model->validate())
		{
			$data = Yii::$app->request->post("ChangecoinForm");
			SysConfig::saveValue($data,$type=18);
            $this->success('修改成功！', ['system/changecoin']);
		}
		else
		{
            $this->error('修改失败！', ['system/changecoin']);
		}
	}

    /**
     * @inheritdoc  app端设置
     */
    public function actionApp()
    {
        return $this->render('app');
    }

    /**
     * @inheritdoc  优化备份
     */
    public function actionBackups()
    {
        return $this->render('backups');
    }

    /**
     * @inheritdoc  ip黑名单
     */
    public function actionIpblack()
    {
	    $model = new IpblackForm();
	    $model ->config_type = 21;
	    $data = $model->getValueByType();
		
	   /* foreach($data as $k=>$v)
	    {
		    $data[$k]['config_value'] = unserialize($v['config_value']);
		    $model->$v['config_key'] = $v['config_value'];
	    }*/
        return $this->render('ipblack',['model'=>$model]);
    }

	/**
	 * @inheritdoc  ip黑名单修改
	 */
	public function actionIpblackadd()
	{
		$model = new IpblackForm();
		if($model->load(Yii::$app->request->post()) && $model->validate())
		{
			$data = Yii::$app->request->post("IpblackForm");
			SysConfig::saveValue($data,$type=21);
            $this->success('修改成功！', ['system/ipblack']);
		}
		else
		{
            $this->error('修改失败！', ['system/ipblack']);
		}
	}

	/**
	 * @inheritdoc  分页方法
	 */
	public function actionPagination($modelname,$where,$pagesize)
	{
		$this->pagination = new Pagination([
			'defaultPageSize' => $pagesize,
			'totalCount' => $modelname
					->find()
					->where($where)
					->count(),
		]);

		$this->model = $modelname
					->find()
					->where($where)
					->offset($this->pagination->offset)
					->limit($this->pagination->limit)
					->asarray()->all();
	}

    /**
     * @inheritdoc  系统日志
     */
    public function actionLogs()
    {
	    $where = "0=0";
	    $admin = new AdminLogForm();
	    $modelname = new AdminLog();
	    $this->actionPagination($modelname,$where,3);
	    foreach($this->model as $k=>$v)
	    {
		     $user_name = Admin::find()
			                    ->select("username")
			                    ->where("id = :id",[':id'=>$v['admin_id']])
			                    ->asArray()
			                    ->one();
		    $this->model[$k]['user_name'] = $user_name['username'];
	    }
	    return $this->render('logs', [
		    'model' => $this->model,
		    'pagination' => $this->pagination,
		    'admin' => $admin,
	    ]);
    }
	/**
	 * @inheritdoc  系统日志分页
	 */
	public function actionLogspage()
	{
		//$page = Yii::$app->request->get("page");
		$where = "0=0";
		$data = Yii::$app->request->get();
		if(!empty($data["log_type"]))
		{
			$where.=" and log_type = ".$data['log_type'];
		}

		if(!empty($data['log_info']))
		{
			$where.=" and log_info like '%".$data['log_info']."%'";
		}

		if(!empty($data['user_name']))
		{
			$username = Admin::find()
						->select("id")
						->where("username = '".$data['user_name']."'")
						->asArray()
						->one();
			$where.=" and admin_id = '".$username['id']."'";
		}

		if(!empty($data['startDateTime']) && !empty($data['endDateTime']))
		{
			$where.=" and log_addtime between ".strtotime($data['startDateTime'])." and ".strtotime($data['endDateTime']);
			goto a;
		}elseif(!empty($data['startDateTime']))
		{
			$where.=" and log_addtime >= ".strtotime($data['startDateTime']);
		}elseif(!empty($data['endDateTime'])){
			$where.=" and log_addtime <= ".strtotime($data['endDateTime']);
		}else{
			$where.="";
		}
		a:
		$admin = new AdminLogForm();
		$modelname = new AdminLog();
		$this->actionPagination($modelname,$where,3);
		foreach($this->model as $k=>$v)
		{
			$this->model[$k]['log_addtime'] = date("Y-m-d H:i:s",$v['log_addtime']);
			$user_name = Admin::find()
				->select("username")
				->where("id = :id",[':id'=>$v['admin_id']])
				->asArray()
				->one();
			$this->model[$k]['user_name'] = $user_name['username'];
		}

		if(!empty($this->model))
		{
			$data['model'] = $this->model;
			$data['pagination'] = LinkPager::widget([
			'pagination' => $this->pagination,
			'firstPageLabel'=>"首页",
			'prevPageLabel'=>'上一页',
			'nextPageLabel'=>'下一页',
			'lastPageLabel'=>'尾页',
		]);
			echo json_encode($data);
		}else{
			echo json_encode(1);
		}

	}
	/**
	 *  @inheritdoc  系统日志用户信息
	 */
	public function actionUsermessage()
	{
		$admin_id = Yii::$app->request->post("admin_id");
		$model = new AdminLog();
		$data = $model->getmessage($admin_id);
		return $this->renderPartial("logmessage",['model'=>$model,'data'=>$data]);
	}
    

    
    
}